home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
apps
/
astronmy
/
strchart.arc
/
patch.arc
/
starst.c
< prev
Wrap
C/C++ Source or Header
|
1989-03-23
|
18KB
|
578 lines
/*
** Atari ST driver for starchart.
** Works on color systems only, compiled with Mark Williams C.
** Written by Dave Yearke (dgy@sigmast), September 1988.
** Portions of this program (c) Mark Williams Company.
** Thanks to the authors of the other starchart drivers for giving
** me some examples to work from.
*/
extern int exit_and_save;
extern char *getenv(), picturefile[];
#include <ctype.h> /* isprint(), iscntrl(), etc. */
#include <linea.h> /* Line A (low-level graphics) routines. */
#include <osbind.h> /* Operating system bindings */
#include <vdibind.h> /* The virtual device interface routines */
#include <xbios.h> /* Extended BIOS bindings */
#include "starchrt.h" /* Starchart information */
/* Global line A variables used by vdi; MUST be included */
int contrl[12], intin[128], ptsin[128], intout[128], ptsout[128];
/* Array used by vs_clip() */
int cliparray[] = { 1, 1, 319, 199 };
/* Arrays used by v_opvwk() */
int work_in[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 };
int work_out[57];
#define TRUE 1
#define NULL 0
/*
** Starchart was designed for 1024x768 pixels. These macros scale the
** image to the 320x200 Atari ST low-resolution (16-color) mode. Also,
** the y coord is subtracted from 200 so the image isn't upside-down.
*/
#define xadjust(x) ((x) * 0.3125)
#define yadjust(y) (200 - ((y) * 0.2604167))
struct la_font *fontp; /* Line A font header. */
char line[100], linemode, *p;
char scr_wrk[1024];
int vdihandle; /* Virtual device's handle */
int CURRX, CURRY, currez, old_color[16], oldrez = 99; /* 99 is impossible! */
/*
** Settings for the palette, given as RGB, 3 bits for each color (512 total).
** I tried to use different registers for different types of objects so they
** could be set individually (for example, in DEGAS you could blink a register
** for an object you're trying to point out).
*/
int new_color[16] = { 0x000, /* Black - Background color */
0x777, /* White - 1st and higher mag. stars */
0x666, /* White - 2nd mag. stars */
0x555, /* White - 3rd mag. stars */
0x444, /* White - 4th mag. stars */
0x333, /* White - 5th mag. stars */
0x222, /* White - 6th and lower mag. stars */
0x222, /* White - Nebulae, Galaxies, Clusters */
0x007, /* Blue - 1st and higher mag. stars */
0x700, /* Red - 1st and higher mag. stars */
0x770, /* Yellow - Sol */
0x704, /* Pink - Inferior Planets */
0x404, /* Purple - Superior Planets */
0x020, /* Dark Green - Dotted lines */
0x200, /* Dark Red - Hyphenated lines */
0x003 }; /* Deep Blue - Text and borders */
/*
** These are reverse-image colors for the background and stars, used when the
** 'r' key is hit when the program pauses before exiting. Switching these
** registers makes a nice output image for a screen dump to a printer.
*/
int rev_color[8] = { 0x777, /* White - Background color */
0x000, /* Black - 1st and higher mag. stars */
0x222, /* Black - 2nd mag. stars */
0x333, /* Black - 3rd mag. stars */
0x444, /* Black - 4th mag. stars */
0x555, /* Black - 5th mag. stars */
0x666, /* Black - 6th and lower mag. stars */
0x666 }; /* Black - Nebulae, Galaxies, Clusters */
/*
** Chart parameters (limiting magnitude and window x,y,w,h)
*/
mapblock thumbnail = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
3.2, 1.0, 2.05, 420, 35, 480, 195, 0.0 };
mapblock master = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
8.0, 2.0, 2.05, 20, 265, 880, 500, 0.0 };
mapblock bigmaster = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
8.0, 2.5, 2.5, 20, 65, 880, 700, 0.0 };
/*
** Generic functions
*/
/*
** Initialize the graphics mode
*/
vecopen()
{
int i;
Cconws("\033H\033J"); /* Clear the screen */
if ((oldrez = Getrez()) == GR_HIGH) {
die("%s\n", "Sorry, this works on color systems only.");
Pterm(1);
} else if (oldrez == GR_MED)
Setscreen((char *)-1, (char *)-1, GR_LOW); /* Set low resolution */
currez = GR_LOW;
appl_init(); /* Initialize the application and register it with AES */
vdihandle = graf_handle(&i, &i, &i, &i); /* Get a VDI handle */
v_opnvwk(work_in, &vdihandle, work_out); /* Open the virtual workscreen */
vs_clip(vdihandle, 1, cliparray); /* Set the clipping rectangle */
for (i = 0; i < 16; i++) /* Save and set the palette */
old_color[i] = Setcolor(i, new_color[i]);
linea0(); /* Initialize the line A routines */
lineaa(); /* Hide mouse pointer */
Cursconf(0, 0); /* Hide cursor */
WMODE = 0; /* Writing mode = replace */
STYLE = 0; /* Normal Letters */
SRCY = 0; /* Y coord of character in font */
LITEMSK = 0x5555; /* Lightening and skewing masks for text */
SKEWMSK = 0x1111;
TEXTFG = 15; /* Text foreground dark blue */
SCRTCHP = scr_wrk; /* Scratch area for graphics */
LNMASK = -1; /* Solid lines */
WEIGHT = 1; /* Thickening factor for lines */
LSTLIN = -1;
}
/*
** Clean up
*/
vecclose ()
{
register int i;
if (exit_and_save)
savepic();
else
while (1) { /* Loop if 'r' is pressed, return for anything else */
switch (i = Crawcin()) { /* Wait for keypress before quitting */
case 'r': /* Reverse the color registers */
if (Setcolor(0, -1) == 0) { /* If normal, reverse it */
for (i = 0; i < 8; i++)
Setcolor(i, rev_color[i]);
} else { /* Make it normal */
for (i = 0; i < 8; i++)
Setcolor(i, new_color[i]);
}
continue; /* Restart the loop */
break;
case 's': /* Save as a DEGAS picture */
strcpy(picturefile, "star.pi1");
savepic();
break;
case 'S': /* Save as a NeoChrome picture */
strcpy(picturefile, "star.neo");
savepic();
break;
default:
break;
}
break;
}
vecreset();
}
/*
** Restore the screen
*/
vecreset()
{
int i;
v_clsvwk(vdihandle); /* Close the virtual workscreen */
appl_exit(); /* Remove the application from AES */
Cconws("\033H\033J"); /* Clear the screen */
Setscreen((char *)-1, (char *)-1, oldrez); /* Set resolution */
for (i = 0; i < 16; i++) /* Set the colors back to their saved values */
Setcolor(i, old_color[i]);
if (((getenv("PATH")) == 0) || (strlen(getenv("PATH")) == 0))
linea9(); /* Show mouse pointer */
else /* If called from a shell */
Cursconf(1, 0); /* Show cursor */
}
/*
** Save the screen as a DEGAS or NeoChrome picture
*/
savepic()
{
int neo = 0, file; /* Assume DEGAS file */
if (strrchr(picturefile, '.') != NULL) { /* Extender given */
if ((!strncmp(picturefile + strrchr(picturefile, '.'), ".neo", 4)) ||
(!strncmp(picturefile + strrchr(picturefile, '.'), ".NEO", 4)))
++neo; /* Save as a NeoChrome picture */
} else
strcat(picturefile, ".pi1");
if ((file = creat(picturefile, 0)) == -1)
die("Cannot open %s.", picturefile);
if (neo) /* NeoChrome has two extra null bytes at the beginning */
if (write(file, &currez, 2) != 2)
die("Write failure on file %s.", picturefile);
if (write(file, &currez, 2) != 2) /* Write the resolution */
die("Write failure on file %s.", picturefile);
if (write(file,